package org.delphy.indy2.controls
{
	import flash.events.MouseEvent;
	
	import mx.controls.Button;
	
	import org.delphy.indy2.core.ICarbonComponent;
	import org.delphy.indy2.layers.FilterFactory;

	public class CarbonButton extends Button implements ICarbonComponent
	{
		/**
		 * @protected
		 */
		protected var upFilters:Array=[];
		
		/**
		 * @protected
		 */
		protected var overFilters:Array=[];
		
		/**
		 * Constructor
		 */
		public function CarbonButton()
		{
			super();
			
			addEventListener(MouseEvent.ROLL_OVER,onRollOver);
			addEventListener(MouseEvent.ROLL_OUT,onRollOut);				
		}
		
		/**
		 * @protected
		 */
		protected function onRollOver(evt:MouseEvent):void{
			
			if(!selected)
				filters=overFilters;
		}
		
		/**
		 * @protected
		 */
		protected function onRollOut(evt:MouseEvent):void{
			filters=upFilters;
		}	
		
		/**
		 * @protected
		 */
		override protected function commitProperties():void{
			super.commitProperties();
			
			if(!styleName)
				styleName="carbonButton";
			
			updateFilters();
			filters=upFilters;
		}
		
		/**
		 * @public
		 */
		public function updateFilters():void{
			upFilters=FilterFactory.createFilters(this,"upFilters");
			overFilters=FilterFactory.createFilters(this, "overFilters");
		}
		
		/**
		 * @public
		 */
		public function get defaultStyleName():String{
			return "carbonButton";
		}
	}
}